package denver.EandSlab.databasetest;

import android.os.Bundle;
import android.app.*;
import android.content.*;
import android.database.sqlite.*;
import android.view.*;
import android.widget.*;


public class ContentTableView extends Activity {
	//declare
	ContentDBHelper cHelper;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.content_table);
		
		
		//---------------------------------db------------------------------
		//make database
		cHelper = new ContentDBHelper(this);
		SQLiteDatabase db;
		db = cHelper.getWritableDatabase();
		//delete previous data in database
		db.delete("dic", null, null);
		ContentValues row = new ContentValues();
		
		//insert data in database
		row.put("ContentName", "love letter");
		db.insert("dic", null, row);
		
		cHelper.close();
		//------------------------------end of db------------------------------
		
		
		//call fack function _ button102 _ "go to the main"
		Button btn = (Button)findViewById(R.id.button102);
		btn.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Intent intent = new Intent(ContentTableView.this, MainActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//add falg into intent (erasing history of activity) [have to add this line with going to MainActivity]
				startActivity(intent);
			}
		}
		); //end button102		
	}//end onCreate
	

	
	
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}





/*
//SQLite Helper Class
class ContentDBHelper extends SQLiteOpenHelper{

	public ContentDBHelper(Context context) {
		super(context, "ContentTable.db", null, 1);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("drop table dic");
		db.execSQL("CREATE TABLE dic ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +  "ContentName TEXT, ContentPrice TEXT);");
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS dic");
		onCreate(db);
		// TODO Auto-generated method stub
		
	}
}
*/